/*
 * TrackFaces.cpp
 *
 *  Created on: Jun 1, 2009
 *      Author: andrei
 */

#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include "gesture_rec.h"


IplImage*     g_gray    = NULL;
int           g_thresh = 100;
CvMemStorage* g_storage = NULL;
CvMemStorage* g_storage2 = NULL;


void closeGestureRec()
{
	cvClearMemStorage(g_storage);
	cvClearMemStorage(g_storage2);
}

void computeVertex(IplImage* source)
{
// On détermine les contours de la main
  if( g_storage==NULL ) {
    g_storage = cvCreateMemStorage(0);
  } else {
    cvClearMemStorage( g_storage );
  }
  CvSeq* contours = 0;
  cvFindContours( source, g_storage, &contours );
  cvZero( source );

  if( contours )
    cvDrawContours( source, contours, cvScalarAll(255), cvScalarAll(255),100);



//Petit test
/*
  if( g_storage2==NULL ) {
    g_storage2 = cvCreateMemStorage(0);
  } else {
    cvClearMemStorage( g_storage2 );
  }
  CvSeq* contours2 = 0;
  cvFindContours( source, g_storage2, &contours2 );
  cvZero( source );
  int n = contours2->total;
  for( int i=0; i< n; ++i ) {
	if (i%10 != 0) {
		cvSeqRemove(contours2,i/10 );
	}
  }

  if( contours2 )
    cvDrawContours( source, contours2, cvScalarAll(255), cvScalarAll(255),100);
  else
	  printf("Enable to create contours");

  cvClearSeq(contours);

  /*
// On calcul les defauts de convexité
  if( g_storage==NULL ) {
  storage = cvCreateMemStorage(0);
  } else {
    cvClearMemStorage( storage );
  }
*/
  /*
int cvCheckContourConvexity(
    const CvArr* contour
);
CvSeq* cvConvexityDefects(
   const CvArr* contour,
   const CvArr* convexhull,
   CvMemStorage* storage    = NULL
);
*/


}

